//  -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Common
//  File name:	ICacheFactory.cs
//  Developer:	Solomatov Igor
//  Created:	15.04.2012
// 
//  -------------------- iSharePoint -------------------- //

using System;
using System.Collections;
using System.Web.Caching;

namespace Smart.Common
{
	/// <summary>
	/// Cache factory
	/// </summary>
	public interface ICacheFactory
	{
		/// <summary>
		/// Return cache value or default
		/// </summary>
		object Get(string key, object Default);

		/// <summary>
		/// Return cache value or load it and add
		/// </summary>
		object Get(string key, TimeSpan absoluteTimeout, TimeSpan slidingExpiration, CacheItemPriority priority, Func<string, object> loader);

		/// <summary>
		/// Format unique key
		/// </summary>
		string GetKey(object[] preValues, bool siteDependent, bool webDependent, bool userDependent, bool urlDependent, string query, object[] postValues);

		/// <summary>
		/// Return all keys names
		/// </summary>
		string[] GetKeys();

		/// <summary>
		/// Remove key from cache
		/// </summary>
		void Remove(string key);

		/// <summary>
		/// Remove keys from cache
		/// </summary>
		void RemoveKeys(string keyStartWith);

		/// <summary>
		/// Set cache value
		/// </summary>
		void Set(string key, object value, TimeSpan timeout, CacheItemPriority priority);

		/// <summary>
		/// Set cache value
		/// </summary>
		void Set(string key, object value, TimeSpan absoluteTimeout, TimeSpan slidingExpiration, CacheItemPriority priority);

		/// <summary>
		/// Default cache value timeout
		/// </summary>
		TimeSpan DefaultTimeout { get; }

		/// <summary>
		/// No sliding expiration
		/// </summary>
		TimeSpan NoSlidingExpiration { get; }

		/// <summary>
		/// Default cache value priority
		/// </summary>
		CacheItemPriority DefaultPriority { get; }

		/// <summary>
		/// Short cache value timeout
		/// </summary>
		TimeSpan ShortTimeout { get; }

		/// <summary>
		/// Long cache value timeout
		/// </summary>
		TimeSpan LongTimeout { get; }

		/// <summary>
		/// Cache store
		/// </summary>
		Cache MainCache { get; }

		/// <summary>
		/// Request store
		/// </summary>
		IDictionary RequestStore { get; }

		/// <summary>
		/// Read request store and if needed load value
		/// </summary>
		object GetRequestItem(string key, Func<object> loader);

		/// <summary>
		/// Clear both cache (Main and Request)
		/// </summary>
		void Clear();

		/// <summary>
		/// Set request store value
		/// </summary>
		void SetRequestItem(string key, object value);

		/// <summary>
		/// Cache clearing notification
		/// </summary>
		event Action CacheClearing;

		/// <summary>
		/// <para>Read request store with loader</para>
		/// </summary>
		TValueType ReadRequestStore<TKeyType, TValueType>(string keyName, TKeyType comparand, string valueName, Func<TKeyType, TValueType> loader);
	}
}